package com.parking.carsystem.parkingchargesystem.activity;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.parking.carsystem.parkingchargesystem.R;
import com.parking.carsystem.parkingchargesystem.module.HomeImageModule;
import com.parking.carsystem.parkingchargesystem.view.PorterShapeImageView;

import java.util.ArrayList;

import butterknife.BindView;
import ttyy.com.recyclerexts.base.EXTRecyclerAdapter;
import ttyy.com.recyclerexts.base.EXTViewHolder;

public class UserCenterActivity extends BaseActivity {
    @BindView(R.id.use_image)
    PorterShapeImageView useImage;
    @BindView(R.id.phone)
    TextView phone;
    @BindView(R.id.safe_image)
    ImageView safeImage;
    @BindView(R.id.list_message)
    RecyclerView listMessage;
    @BindView(R.id.user_function)
    RecyclerView userFunction;
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.text)
    TextView text;
    private EXTRecyclerAdapter<HomeImageModule> recyclerAdapter;
    private ArrayList<HomeImageModule> imageModules;
    ArrayList<String> listfunctions;
    private EXTRecyclerAdapter<String> listFunctionsAdapter;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_usercenter;
    }

    @Override
    public void initView() {
        text.setText("个人中心");
        back.setVisibility(View.VISIBLE);
       /* Glide.with(this.getApplicationContext())
                .load(imageUrl)
                .asBitmap()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                .placeholder(R.drawable.ic_user)
                .placeholder(R.drawable.ic_user)
                .into(user_image);*/
    }

    @Override
    public void initData() {
        if (imageModules == null) {
            imageModules = new ArrayList<>();
            HomeImageModule homeImageModule = new HomeImageModule();
            homeImageModule.imageId = R.mipmap.icon_user_car;
            homeImageModule.name = "车辆管理";
            imageModules.add(homeImageModule);
            HomeImageModule homeImageModule1 = new HomeImageModule();
            homeImageModule1.imageId = R.mipmap.icon_user_coupon;
            homeImageModule1.name = "优惠卷";
            imageModules.add(homeImageModule1);
            HomeImageModule homeImageModule2 = new HomeImageModule();
            homeImageModule2.imageId = R.mipmap.icon_user_month;
            homeImageModule2.name = "我的月卡";
            imageModules.add(homeImageModule2);
            HomeImageModule homeImageModule3 = new HomeImageModule();
            homeImageModule3.imageId = R.mipmap.icon_user_money;
            homeImageModule3.name = "用户充值";
            imageModules.add(homeImageModule3);
        }
        listMessage.setLayoutManager(new GridLayoutManager(this, 4));
        recyclerAdapter = new EXTRecyclerAdapter<HomeImageModule>(R.layout.item_user_image) {
            @Override
            public void onBindViewHolder(EXTViewHolder extViewHolder, int i, HomeImageModule module) {
                HomeImageModule homeImageModule = imageModules.get(i);
                extViewHolder.setImageResouce(R.id.image, homeImageModule.imageId);
                extViewHolder.setText(R.id.name, homeImageModule.name);
            }
        };
        recyclerAdapter.setDatas(imageModules);
        listMessage.setAdapter(recyclerAdapter);
        recyclerAdapter.setOnItemClickListener(new EXTRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClicked(View view, int i) {
                Intent intent = null;
                //点击事件
                if (i == 1) {
//                    intent = new Intent(UserCenterActivity.this, MapActivity.class);
//                    startActivity(intent);
                } else if (i == 0) {

                } else if (i == 2) {
                    intent = new Intent(UserCenterActivity.this, MonthlySubscriptionActivity.class);
                    startActivity(intent);
                } else if (i == 3) {
                    intent = new Intent(UserCenterActivity.this, UserRechargeActivity.class);
                    startActivity(intent);
                }
            }
        });
        if (listfunctions == null) {
            listfunctions = new ArrayList<>();
        }
        listfunctions.add(getResources().getString(R.string.my_wallet));
        listfunctions.add(getResources().getString(R.string.real_name_authentication));
        listfunctions.add(getResources().getString(R.string.invoice_information));
        listfunctions.add(getResources().getString(R.string.privacy_free_login));
        listfunctions.add(getResources().getString(R.string.help_center));
        listfunctions.add(getResources().getString(R.string.contact_customer_service));
        listfunctions.add(getResources().getString(R.string.about_us));
        userFunction.setLayoutManager(new LinearLayoutManager(this));
        listFunctionsAdapter = new EXTRecyclerAdapter<String>(R.layout.item_list_function) {
            @Override
            public void onBindViewHolder(EXTViewHolder extViewHolder, int i, String s) {
                extViewHolder.setText(R.id.text, s);
            }
        };
        listFunctionsAdapter.setDatas(listfunctions);
        userFunction.setAdapter(listFunctionsAdapter);
        listFunctionsAdapter.setOnItemClickListener(new EXTRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClicked(View view, int i) {
                Intent intent = null;
                if (i == 2) {
                    //开票信息
                    intent = new Intent(UserCenterActivity.this, InvoiceMessageActivity.class);
                    startActivity(intent);
                }else if (i == 3){
                    intent = new Intent(UserCenterActivity.this,PaySettingActivity.class);
                    startActivity(intent);
                }
            }
        });
    }
}
